apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/component: controller
    app.kubernetes.io/name: prometheus-operator
    app.kubernetes.io/part-of: kube-prometheus
    app.kubernetes.io/version: {{ prometheus_operator_tag | replace("v", "") }}
  name: prometheus-operator
  namespace: kubesphere-monitoring-system
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/component: controller
      app.kubernetes.io/name: prometheus-operator
      app.kubernetes.io/part-of: kube-prometheus
  template:
    metadata:
      annotations:
        kubectl.kubernetes.io/default-container: prometheus-operator
      labels:
        app.kubernetes.io/component: controller
        app.kubernetes.io/name: prometheus-operator
        app.kubernetes.io/part-of: kube-prometheus
        app.kubernetes.io/version: {{ prometheus_operator_tag }}
    spec:
      containers:
      - args:
        - --kubelet-service=kube-system/kubelet
        - --prometheus-config-reloader={{ prometheus_config_reloader_repo }}:{{ prometheus_config_reloader_tag }}
        image: {{ prometheus_operator_repo }}:{{ prometheus_operator_tag }}
        name: prometheus-operator
        ports:
        - containerPort: 8080
          name: http
        resources:
          limits:
            cpu: {{ monitoring.prometheus.operator.resources.limits.cpu | default("200m") }}
            memory: {{ monitoring.prometheus.operator.resources.limits.memory | default("200Mi") }}
          requests:
            cpu: {{ monitoring.prometheus.operator.resources.requests.cpu | default("100m") }}
            memory: {{ monitoring.prometheus.operator.resources.requests.memory | default("100Mi") }}
        securityContext:
          allowPrivilegeEscalation: false
      - args:
        - --logtostderr
        - --secure-listen-address=:8443
        - --tls-cipher-suites=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_RSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
        - --upstream=http://127.0.0.1:8080/
        image: {{ kube_rbac_proxy_repo }}:{{ kube_rbac_proxy_tag }}
        name: kube-rbac-proxy
        resources:
          limits:
            cpu: {{ monitoring.kube_rbac_proxy.resources.limits.cpu | default(monitoring.kube_rbac_proxy.limits.cpu) | default("1") }}
            memory: {{ monitoring.kube_rbac_proxy.resources.limits.memory | default(monitoring.kube_rbac_proxy.limits.memory) | default("100Mi") }}
          requests:
            cpu: {{ monitoring.kube_rbac_proxy.resources.requests.cpu | default(monitoring.kube_rbac_proxy.requests.cpu) | default("10m") }}
            memory: {{ monitoring.kube_rbac_proxy.resources.requests.memory | default(monitoring.kube_rbac_proxy.requests.memory) | default("20Mi") }}
        ports:
        - containerPort: 8443
          name: https
        securityContext:
          runAsGroup: 65532
          runAsNonRoot: true
          runAsUser: 65532
{% if monitoring.nodeSelector is defined and monitoring.nodeSelector is not none %}
      nodeSelector:
        {{ monitoring.nodeSelector | to_nice_yaml(indent=2) | indent(8) }}
{% elif nodeSelector is defined and nodeSelector is not none %}
      nodeSelector:
        {{ nodeSelector | to_nice_yaml(indent=2) | indent(8) }}
{% else %}
      nodeSelector:
        kubernetes.io/os: linux
{% endif %}
{% if monitoring.tolerations is defined and monitoring.tolerations is not none %}
      tolerations:
        {{ monitoring.tolerations | to_nice_yaml(indent=2) | indent(8) }}
{% elif tolerations is defined and tolerations is not none %}
      tolerations:
        {{ tolerations | to_nice_yaml(indent=2) | indent(8) }}
{% else %}
      tolerations: []
{% endif %}
{% if monitoring.affinity is defined and monitoring.affinity is not none %}
      affinity:
        {{  monitoring.affinity | to_nice_yaml(indent=2) | indent(8) }}
{% elif affinity is defined and affinity is not none %}
      affinity:
        {{ affinity | to_nice_yaml(indent=2) | indent(8) }}
{% else %}
      affinity: {}
{% endif %}
      securityContext:
        runAsNonRoot: true
        runAsUser: 65534
      serviceAccountName: prometheus-operator
